package com.hyz.controller;

import com.hyz.model.LoginUser;
import com.hyz.model.User;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author HGD
 * @date 2022/9/15 15:50
 */

@RestController
@RequestMapping("/demo")
@PreAuthorize("hasAuthority('rights')")
public class HelloController {
    @GetMapping("/hello")
    public String hello() {
        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        User user = ((LoginUser) principal).getUser();
        System.out.println(user);
        return "hello SpringSecurity";
    }
}
